/*!
 * \file:%{Cpp:License:FileName}
 * \brief:文件说明
 * \version:v1.0
 * \author:郭智隆
 * \date:2017-11-29
 * \b 修改说明
 * \i $修改日期$
 * $修改记录$
 */
#include <QCoreApplication>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <iostream>
#include <QThread>
using namespace std;
extern char **environ;
enum{
    START = 0,
    WAIT,
    STOPPING,
};
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    int status = 0, mode = START;
    pid_t pid ;

    while(1)
    {
        switch(mode)
        {
        case START:
            pid = fork();
            if(!pid)
            {
                //execle("./textErrorProcess","",NULL , environ);
                cout << "execle:"<< execle("./textErrorProcessd","",NULL , environ) << endl;
            }
            if(pid > 0)
                mode = WAIT;
            break;
        case WAIT:
            if(waitpid(pid, &status, 0) < 0)
            {
                mode = START;
                break;
            }
            else if(WIFSIGNALED(status)||WIFSTOPPED(status)||WIFEXITED(status))
            {
                mode = START;
            }else{
                mode = WAIT;
            }
            break;
        default:
            break;
        }
        QThread::usleep(500);
    }
    return a.exec();
}
